//
//  BuildingData.m
//  Model
//
//  Created by YDJH on 2017/5/19.
//  Copyright © 2017年 YDJH. All rights reserved.
//

#import "BuildingData.h"
#import "RoomData.h"
#import "HZBuilding.h"

@implementation BuildingData

+ (NSMutableArray *)gobackBuildingModel {
    
    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:@"BuildingData" ofType:@"plist"];
    NSArray *array= [[NSArray alloc] initWithContentsOfFile:plistPath1];
    
    NSMutableArray *mutableArr = [NSMutableArray array];
    for (NSDictionary *dict in array) {
        BuildingData *model = [BuildingData new];
        model.buildID = dict[@"buildingID"];
        model.buildType = dict[@"type"];
        model.buildName = dict[@"buildingtype"];
        model.insideRoomType = dict[@"insideRoomType"];
        model.buildLobby = dict[@"insideLobby"];
        model.outsideRoomType = dict[@"outsideRoomType"];
        model.outsideFurniture = dict[@"outsideFurniture"];
        model.structure = dict[@"buildingConstruct"];
        model.sandTableFurniture = dict[@"sandTableFurniture"];
        
        model.outsideBackWallPicture = dict[@"outsideBackWallPicture"];
        model.outsideLeftWallPicture = dict[@"outsideLeftWallPicture"];
        model.outsideMainWallPicture = dict[@"outsideMainWallPicture"];
        model.outsideRightWallPicture = dict[@"outsideRightWallPicture"];
        model.outsideMainWallFurniture = dict[@"outsideMainWallFurniture"];
        
        if (model.outsideRoomType.count>0) {
            model.isHaveOutsideRoom = YES;
        }else {
            model.isHaveOutsideRoom = NO;
        }
        if (model.buildLobby !=nil && model.buildLobby.count > 0) {
            model.isHavaInsideLobby = YES;
        }else {
            model.isHavaInsideLobby = NO;
        }
        
        [mutableArr addObject:model];
    }
    return mutableArr;
    
}



+ (HZConstruction *)gobackConsturctionModelWithModel:(BuildingData *)buildingData {
    HZConstruction *construction = [[HZConstruction alloc] init];
    construction.type = buildingData.buildType;
    construction.constructionID = buildingData.buildID;
    construction.name = buildingData.buildName;

    return construction;
}

+ (BOOL)containsTSandable:(BuildingData *)buildingData {
    
    BOOL contains = buildingData.outsideRoomType.count > 0;
    
    return contains;
}


// 返回沙盘上的建筑模型
+ (NSMutableArray *)gobackBuildingWithSandTable:(NSArray *)outsidehiddenArr withData:(BuildingData *)data withRoomArr:(NSArray *) roomArr {
    
    NSMutableArray *dataArr = [NSMutableArray array];
    NSInteger index = 0;
    for (HZHiddenFurniture *hiddenFur in outsidehiddenArr) {
        //楼
        if ([hiddenFur.type isEqualToString:HiddenFurType_Building]) {
            hiddenFur.index = index;
            
            HZBuilding *building = [[HZBuilding alloc] init];
            building.type = data.buildType;
            building.buildingID = data.buildID;
            building.structure = data.structure;
            building.position = hiddenFur.position;
            building.isHavaInsideLobby = data.isHavaInsideLobby;
            building.buildingData = data;
            for (RoomData *roomData in roomArr) {
                if ([roomData.type isEqualToString:hiddenFur.buildingType]) {
                    building.name = roomData.name;
                    break;
                }
            }
            
            building.buildingStructure = [RoomData gobackRoomArrWithBuildingData:data withRoomArr:roomArr];
            
            [dataArr addObject:building];
            
            index++;
        }
        
    }
   return dataArr;
}
// 返回一个建筑物模型
+ (HZBuilding *)goBackBuildingWithData:(BuildingData *)data withRoomArr:(NSArray *) roomArr {

    HZBuilding *building = [[HZBuilding alloc] init];
    building.type = data.buildType;
    building.buildingID = data.buildID;
    building.structure = data.structure;
    building.isHavaInsideLobby = data.isHavaInsideLobby;
    building.name = data.buildName;
    building.buildingData = data;
    building.buildingStructure = [RoomData gobackRoomArrWithBuildingData:data withRoomArr:roomArr];
    
    return building;
}
+ (NSArray *)gobackOutDoorWithSandTable:(NSArray *)outsidehiddenArr withData:(NSArray *)roomArr {
    NSMutableArray *dataArr = [NSMutableArray array];
    NSInteger index = 0;
    for (HZHiddenFurniture *hiddenFur in outsidehiddenArr) {
        if ([hiddenFur.type isEqualToString:HiddenFurType_Outdoor]) {
            hiddenFur.index = index;
            
            HZOutDoor *outdoor = [[HZOutDoor alloc] init];
            outdoor.type = hiddenFur.buildingType;
            outdoor.position = hiddenFur.position;
            outdoor.picture = [NSString stringWithFormat:@"outdoor_%@",outdoor.type];
            
            for (RoomData *roomData in roomArr) {
                if ([roomData.type isEqualToString:hiddenFur.buildingType]) {
                    outdoor.name = roomData.name;
                    break;
                }
            }
            [dataArr addObject:outdoor];
            index++;
        }
    }
    return dataArr;
}

@end
